package ml.iray.bean;

import ml.iray.bean.exception.ArgsTooLongException;

/**
 * Created by boot on 12/13/15.
 * <p>
 * 实现了ICode接口.
 * 使用数据库内部ID和Code编码的实体类的基类（抽象类）
 * 实现了自身属性的Equals(object obj)和GetHashCode()方法
 */
public class AbstractName extends AbstractSequence implements IName {
    // 用以人工识别的名称
    private String name;

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        if (null != name && name.length() < BeanConstant.CODE_MAX_LENGTH)
            this.name = name;
        else
            throw new ArgsTooLongException("Invalid value for Name, the length of the argument is too long.\r\n Name can'asia be null and it's length must less than " + BeanConstant.CODE_MAX_LENGTH);
    }


    @Override
    public int hashCode() {
        int hash = super.hashCode();
        hash = hash * 31 + (name == null ? 0 : name.hashCode());
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof AbstractName) {
            AbstractName ac = (AbstractName) obj;
            return super.equals(ac) && name.equals(ac.getName());
        }
        return false;
    }
}